import React from 'react'
import { connect } from 'react-redux'

// import Layout from '@/components/Layout'
import Search from '@/components/Search'
import TabTop from '@/components/TabTop'
import AreaMci from '@/components/AreaMci'
import PK from '@/components/PK'
// import HotReview from '@/components/HotReview'
// import HotWords from '@/components/HotWords'
// import BottomBanner from '@/components/BottomBanner'
// import TabBottom from '@/components/TabBottom'
import { cityList, userComment, hotwordsToday, fastestBrand, mbiNavigation } from '@/store/actions'
import {browserRedirect} from '../utils'

// export const getServerSideProps = async(context) => {
//   console.log(context);
//   return {
//     props: {

//     }
//   }
// }

class Counter extends React.Component {
  
  static async getInitialProps  (ctx) {
    const { store, isServer } = ctx;
    console.log(ctx);
    const cl =  store.dispatch(cityList(isServer));
    const uc = store.dispatch(userComment({
      isServer, id: 0, type: 1, commentType: 4,
      currentPage: 1, displayCount: 8
    }));
    const ht = store.dispatch(hotwordsToday(isServer));
    const fb = store.dispatch(fastestBrand(isServer));
    const mbiT = store.dispatch(mbiNavigation({isServer}))
    await Promise.all([cl,  ht, fb, mbiT]);
    // 城市
    // await store.dispatch(cityList(isServer))
    // 今日热评推介
    // await store.dispatch(userComment({
    //   isServer, id: 0, type: 1, commentType: 4,
    //   currentPage: 1, displayCount: 8
    // }))
    // 今日热词
    // await store.dispatch(hotwordsToday(isServer))
    // 上升最快的品牌酒店
    // await store.dispatch(fastestBrand(isServer))
  }
  componentDidMount() {
    // browserRedirect('');
  }
  UNSAFE_componentWillReceiveProps(nextprops) {
    const {searchType, scrollTop} = nextprops;
    if (searchType) {
      document.body.classList.add('no-scroll')
    } else {
      document.body.classList.remove('no-scroll')
      window.scrollTo(0, scrollTop)
    }
  }
  render () {
    return (
      <>
        <Search></Search>
        <TabTop></TabTop>
        <AreaMci></AreaMci>
        <PK></PK>
        {/*<HotReview></HotReview>
        <HotWords/>
        <BottomBanner></BottomBanner>
        <p className="height"></p> 
        <TabBottom selectedTab="首页" ></TabBottom> */}
      </>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    searchType: state.searchType,
    scrollTop: state.scrollTop,
    hotWords: state.hotWords,
  }
}

export default connect(mapStateToProps)(Counter);